<template>
  <el-radio-group v-model="_value" :disabled="disabled">
    <el-radio :label="item.label" v-for="item in weeklyRoles" :key="item.label">{{ item.name }}</el-radio>
  </el-radio-group>
</template>

<script>
/**
 * h-radio-weekly
 * @module common/h-radio-weekly
 * @desc 选择一周内的某以天单选
 *
 * @param { number } value - 已选中的日子，:value.sync绑定
 */
export default {
  name: 'h-radio-weekly',
  componentName: 'h-radio-weekly',
  data () {
    return {
      weeklyRoles: []
    }
  },
  props: {
    value: [Number, String],
    disabled: Boolean
  },
  computed: {
    _value: {
      get () {
        return this.value
      },
      set (val) {
        this.$emit('update:value', val)
        this.$emit('change', val)
      }
    }
  },
  methods: {
    setWeeklyRoles () {
      let i = 1
      let n = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
      let tmp = []
      while (i < 8) {
        tmp.push({
          label: i,
          name: n[i - 1]
        })
        i++
      }
      this.weeklyRoles = tmp
    }
  },
  created () {
    this.setWeeklyRoles()
  }
}
</script>
